<!DOCTYPE html>
<html>
    {include file="Widgets/head" /}
    <body class="gray-bg">
        <div class="wrapper wrapper-content animated fadeInUp">
            <div class="row">
                <div class="col-sm-12">
                    <div class="ibox">
                        <div class="ibox-title">
                            <h3>还款管理-待还款</h3>
                        </div>
                        <div class="ibox-content">
                            <div class="row m-b-sm m-t-sm">
                                <div class="row">
                                    <label class="col-sm-1 control-label text-right">可用金额：</label>
                                    <div class="col-sm-2">
                                        {$total}元
                                    </div>
<!--                                    <a class="btn btn-white col-sm-1" data-toggle="modal" data-target="#myModal2">充值</a>-->
                                </div>
                                <div class="hr-line-dashed"></div>
                                <div class="row">  
                                    <label class="pull-left control-label col-sm-1" style="text-align:right;" for="planned_repay_time_start">还款时间：</label>
                                    <a href="{:url('Repayment/waitRepayment', ['planned_repay_time'=>'1'])}" class="col-sm-1" style="text-align:center;">
                                        今日应还
                                    </a>
                                    <a href="{:url('Repayment/waitRepayment', ['planned_repay_time'=>'2'])}" class="col-sm-1" style="text-align:center;">
                                        次日应还
                                    </a>
                                    <a href="{:url('Repayment/waitRepayment', ['planned_repay_time'=>'3'])}" class="col-sm-1" style="text-align:center;">
                                        后天应还
                                    </a>
                                    <a href="{:url('Repayment/waitRepayment', ['planned_repay_time'=>'4'])}" class="col-sm-1" style="text-align:center;">
                                        近七日应还
                                    </a>
                                </div>
                                <div class="hr-line-dashed"></div>
                                <form action="{:url('Repayment/waitRepayment')}" method="post" class="form-horizontal">
                                    <div class="form-group">
                                        <label class="pull-left control-label col-sm-1" style="text-align:right;" for="planned_repay_time_start">还款时间：</label>
                                        <div class="col-sm-2">
                                            <input type="date" id="planned_repay_time_start" name="planned_repay_time_start"
                                                   value="{$planned_repay_time_start}"
                                                   class="form-control laydate-icon input-s-sm inline layer-date"
                                                   onclick="laydate({istime: false, format: 'YYYY-MM-DD'})">
                                        </div>
                                        <label class="pull-left control-label col-sm-1" style="text-align:center;" for="planned_repay_time_end">-</label>
                                        <div class="col-sm-2">
                                            <input type="date" id="planned_repay_time_end" name="planned_repay_time_end"
                                                   value="{$planned_repay_time_end}"
                                                   class="form-control laydate-icon input-s-sm inline layer-date"
                                                   onclick="laydate({istime: false, format: 'YYYY-MM-DD'})">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label" style="text-align:right;" for="borrower_name">借款人：</label>
                                        <div class="col-sm-2 m-b-xs">
                                            <input type="text" id="borrower_name" name="borrower_name" value="{$borrower_name}" class="form-control input-s-sm inline" placeholder="借款人">
                                        </div>
                                        <label class="col-sm-1 control-label" style="text-align:center;" for="title">关联标的：</label>
                                        <div class="col-sm-2 m-b-xs">
                                            <input type="text" id="title" name="title" value="{$title}" class="form-control input-s-sm inline" placeholder="关联标的">
                                        </div>
                                        <label class="col-sm-1 control-label" for="repayment_type" style="text-align:right;">还款方式：</label>
                                        <div class="col-sm-2 m-b-xs">
                                            <select id="repayment_type" name="repayment_type" class="form-control input-s-sm inline">
                                                {foreach $repayment_type_list as $key => $val} 
                                                <option value="{$key}" {if ($repayment_type == $key)} selected {/if}>{$val}</option>
                                                {/foreach}
                                            </select>
                                        </div>
                                        <div class="col-sm-1">
                                            <button class="btn btn-primary" type="submit">查询</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="row">
                                <label class="col-sm-1 control-label text-left">今日应还：</label>
                                <div class="col-sm-2">
                                    {$today_pay}
                                </div>
                                <label class="col-sm-1 control-label text-left">总计应还：</label>
                                <div class="col-sm-2">
                                    {$total_pay}
                                </div>
                            </div>
                            <table class="table table-bordered table-hover">
                                <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>借款人</th>
                                        <th>关联标的</th>
                                        <th>借款金额</th>
                                        <th>借款期限（天）</th>
                                        <th>总成本利率</th>
                                        <th>还款方式</th>
                                        <th>应还利息 </th>
                                        <th>总计应还金额</th>
                                        <th>投资人</th>
                                        <th>投资时间</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {if ($list)}
                                    {foreach $list as $key => $val} 
                                    <tr class="gradeA odd">
                                        <td>{$key + 1}</td>
                                        <td>{$val.borrower_name}</td>
                                        <td>{$val.title}</td>
                                        <td>{$val.amount}</td>
                                        <td>{$val.duration}</td>
                                        <td>{$val.interest_rate}%</td>
                                        <td>{$val.repayment_type}</td>
                                        <td>{$val.interest}</td>
                                        <td>{$val.total}</td>
                                        <td>{$val.real_name}</td>
                                        <td>{$val.create_time}</td>
                                        <td>
                                            <a class="btn btn-white reply_plans" data-val="{$val.id}">还款计划 </a>
                                        </td>
                                    </tr>
                                    {/foreach}                            
                                    {else /}
                                    <tr class="gradeA odd">
                                        <td style="text-align:center;" colspan="12">没有找到符合条件的记录</td>
                                    </tr>
                                    {/if}
                                </tbody>
                                <tfoot>
                                </tfoot>
                            </table>
                            {//分页}
                            <div>
                                <div class="row">
                                    {$paginator}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog" style="width:700px">
                <div class="modal-content" >
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"
                                aria-hidden="true">×
                        </button>
                        <h4 class="modal-title" id="myModalLabel">
                            还款计划
                        </h4>
                    </div>
                    <div class="modal-body">
                        <div class="row">
                            <table class="table table-striped table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th>计划还款日期</th>
                                    <th>计划还款本金</th>
                                    <th>计划还款利息</th>
                                    <th>需还本息</th>
                                    <th>实还本息</th>
                                    <th>还款状态</th>
                                </tr>
                                </thead>
                                <tbody id="add_borrow_reply">
                                </tbody>
                            </table>
                        </div>
                        <div class="row">
                            提前还款金额=剩余应还金额+实际利息
                        </div>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div>
        
        <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <form action="{:url('Merchant/recharge')}" method="post">
                    <input type="hidden" name="url" value="Repayment/waitRepayment" >
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel">充值</h4>
                    </div>
                    <div class="modal-body">
                        <div class="form-group  ">
                            <label class="col-sm-1 control-label"></label>
                            <label class="col-sm-3 control-label text-right">充值金额：</label>
                            <div class="col-sm-6">
                                <div class="row">
                                    <div class="col-md-8">
                                        <input type="text" class="form-control required"   name="money" value=""   onkeyup="(this.v=function(){this.value=this.value.replace(/[^0-9-]+/,'');}).call(this)" onblur="this.v();" placeholder="">
                                        <span class="help-block m-b-none"></span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <input  type="submit" class="btn btn-primary">
                    </div>
                </div><!-- /.modal-content -->
                </form>
            </div><!-- /.modal -->
        </div>
    </body>
    <script>
        $(".reply_plans").click(function () {
        var id = $(this).data('val');
        $.ajax({
            type: 'get',
            url: "{:url('Repayment/getBorrowReplyListAjax')}",
            data: {id: id},
            success: function (data) {
                if(data.code==1){
                    if(data.data.length<1){
                        alert('数据不存在'); return false;
                    }else{
                        var html = "";
                        $("#add_borrow_reply").html("");//清空先，不然会在原先的基础上继续追加
                        for(var i=0;i<data.data.length;i++){
                            html =html+"<tr>";
                            html =html+"<td>"+data.data[i].planned_repay_time+"</td>";
                            html =html+"<td>"+data.data[i].capital+"</td>";
                            html =html+"<td>"+data.data[i].interest+"</td>";
                            html =html+"<td>"+data.data[i].total+"</td>";
                            html =html+"<td>"+data.data[i].total+"</td>";
                            html =html+"<td>"+data.data[i].status+"</td>";
                            html =html+"</tr>";
                        }
                        $("#add_borrow_reply").append(html);

                        $('#myModal').modal('show');
                    }
                }else{
                    alert('ajax error'); return false;
                }                    
            }
        });
    });
    </script>
</html>

